-- Tags: no-fasttest, no-random-settings
-- - no-fasttest -- requires S3
-- - no-random-settings -- prefetch is non deterministic

drop table if exists test;

{% for disk in ['default', 's3_disk'] %}
-- Need wide parts to enable prefetch
create table test (key Int) engine=MergeTree() order by () settings min_bytes_for_wide_part=0, disk = '{{ disk }}';
-- Need at least 2 parts
system stop merges test;
insert into test values (1);
insert into test values (2);
select * from test settings local_filesystem_read_prefetch=1, enable_filesystem_read_prefetches_log=1, allow_prefetched_read_pool_for_local_filesystem=1, local_filesystem_read_method='pread_threadpool' format Null settings log_comment = '{{ disk }}';
system flush logs filesystem_read_prefetches_log, query_log;
with (
    select query_id
    from system.query_log
    where current_database = currentDatabase()
      and log_comment = '{{ disk }}'
      and type != 'QueryStart'
) as initial_query_id_,
query_ids_ as (
    select query_id
    from system.query_log
    where initial_query_id = initial_query_id_
      and log_comment = '{{ disk }}'
      and type != 'QueryStart'
)
select '{{ disk }}', count()>0
from system.filesystem_read_prefetches_log
where query_id in (query_ids_);
drop table test;
{% endfor %}
